package com.szh.controller;

import com.szh.domain.OrderInfo;
import com.szh.enums.OrderStatus;
import com.szh.service.OrderInfoService;
import com.szh.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 */
@Api(tags = "订单管理")
@CrossOrigin
@RestController
@RequestMapping("/api/orderInfo")
public class OrderInfoController {

    private static final Logger LOGGER = LoggerFactory.getLogger(OrderInfoController.class);

    @Autowired
    private OrderInfoService orderInfoService;

    @ApiOperation("查询订单列表，按照创建时间倒序")
    @GetMapping("/list")
    public R list() {
        List<OrderInfo> orderInfoList = orderInfoService.listOrderByCreateTimeDesc();
        return R.ok().data("orderInfoList", orderInfoList);
    }

    @ApiOperation(value = "根据订单号查询订单状态")
    @GetMapping(value = "/queryOrderStatus/{orderNo}")
    public R queryOrderStatus(@ApiParam(name = "orderNo", value = "订单号", required = true)
                              @PathVariable("orderNo") String orderNo) {
        String orderStatus = orderInfoService.queryOrderStatus(orderNo);
        if (OrderStatus.SUCCESS.getType().equals(orderStatus)) {
            return R.ok().setMessage("支付成功");
        } else {
            return R.ok().setCode(101).setMessage("支付中....");
        }
    }
}
